package com.xy.p2p.action.front;



import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.math.NumberUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.octo.captcha.service.CaptchaServiceException;
import com.octo.captcha.service.image.ImageCaptchaService;
import com.xy.common.page.Pagination;
import com.xy.common.util.DictUtils;
import com.xy.common.security.BadCredentialsException;
import com.xy.common.security.UsernameNotFoundException;
import com.xy.common.web.CookieUtils;
import com.xy.common.web.RequestUtils;
import com.xy.core.util.DateUtil;
import com.xy.core.web.WebErrors;

import com.xy.p2p.dao.TyedtransferoutDao;
import com.xy.p2p.model.Tfinanceinfo;
import com.xy.p2p.model.Tmember;
import com.xy.p2p.model.Tnoticeinfor;
import com.xy.p2p.model.Tyedtransferout;
import com.xy.p2p.service.TfinanceinfoService;
import com.xy.p2p.service.TnoticeinforService;



@Controller
public class IndexAction{
	private static final Logger log = LoggerFactory.getLogger(IndexAction.class);
	public IndexAction() {
	}

	@RequestMapping("/index.jspx")
	public String info(HttpServletRequest request, ModelMap model) {
		model.addAttribute("tfinanceinfos", tfinanceinfoService.getEnableFinance());  
		Map<String,Object>	nomap = new HashMap<String, Object>();
		nomap.put("status", 1);
		List<Tnoticeinfor> list = tnoticeinforService.getTnoticeinfor(nomap);
		Collections.sort(list);
		model.addAttribute("tnoticeinfors",list);
        setDict(model);
        List<Tfinanceinfo> ylist = tfinanceinfoService.getYED();
//        Collections.sort(ylist);
        model.addAttribute("yeds", ylist);
		return "/front/index.html";
	}
	@RequestMapping("/header.jspx")
	public String header(HttpServletRequest request, ModelMap model) {
		if(null!=request.getSession().getAttribute(TmemberAction.AUTH_KEY)){
			model.addAttribute("tmember", (Tmember)request.getSession().getAttribute(TmemberAction.AUTH_KEY));
		}
		return "/front/common/header.html";
	}
	
	@RequestMapping("/help/helpdyd.jspx")
	public String helpdyd(HttpServletRequest request,ModelMap model){
		return "/front/help/helpdyd.html";
	}
	
	@RequestMapping("/help/helpinterest.jspx")
	public String helpinterest(HttpServletRequest request,ModelMap model){
		return "/front/help/helpinterest.html";
	}
	
	@RequestMapping("/help/helpinvest.jspx")
	public String helpinvest(HttpServletRequest request,ModelMap model){
		return "/front/help/helpinvest.html";
	}
	
	@RequestMapping("/help/helpnounExplain.jspx")
	public String helpnounExplain(HttpServletRequest request,ModelMap model){
		return "/front/help/helpnounExplain.html";
	}
	
	@RequestMapping("/help/helpfinancing.jspx")
	public String helpfinancing(HttpServletRequest request,ModelMap model){
		return "/front/help/helpfinancing.html";
	}

	@RequestMapping("/help/helpbalance.jspx")
	public String helpbalance(HttpServletRequest request,ModelMap model){
		return "/front/help/helpbalance.html";
	}
	
	@RequestMapping("/about/contact.jspx")
	public String contact(HttpServletRequest request,ModelMap model){
		return "/front/about/contact.html";
	}
	
	@RequestMapping("/about/terraceInterface.jspx")
	public String terraceInterface(HttpServletRequest request,ModelMap model){
		return "/front/about/terraceInterface.html";
	}
	@RequestMapping("/about/recruit.jspx")
	public String recruit(HttpServletRequest request,ModelMap model){
		return "/front/about/recruit.html";
	}
	
	@RequestMapping("/about/cooperation.jspx")
	public String cooperation(HttpServletRequest request,ModelMap model){
		return "/front/about/cooperation.html";
	}
	@RequestMapping("/about/team.jspx")
	public String team(HttpServletRequest request,ModelMap model){
		return "/front/about/team.html";
	}
	@RequestMapping("/about/media.jspx")
	public String media(HttpServletRequest request,ModelMap model){
		return "/front/about/media.html";
	}
	@RequestMapping("/about/performance.jspx")
	public String performance(HttpServletRequest request,ModelMap model){
		return "/front/about/performance.html";
	}
	
	@RequestMapping("/about/society.jspx")
	public String society(HttpServletRequest request,ModelMap model){
		return "/front/about/society.html";
	}

	@RequestMapping("/about/aboutPapers.jspx")
	public String aboutPapers(HttpServletRequest request,ModelMap model){
		return "/front/about/aboutPapers.html";
	}
	@RequestMapping("/about/aboutSetting.jspx")
	public String aboutSetting(HttpServletRequest request,ModelMap model){
		return "/front/about/aboutSetting.html";
	}
	
	@RequestMapping("/integrity.jspx")
	public String integrity(HttpServletRequest request,ModelMap model){
		return "/front/integrity.html";
	}
	
	@RequestMapping("/friendship.jspx")
	public String friendship(HttpServletRequest request,ModelMap model){
		return "/front/friendship.html";
	}
	
	@RequestMapping("/map.jspx")
	public String map(HttpServletRequest request,ModelMap model){
		return "/front/map.html";
	}
	
	
	private void setDict(ModelMap model){
	      model.addAttribute("repaymentperiodMap", DictUtils.getDictByType(DictUtils.TFINANCEINFO_REPAYMENTPERIOD));
	      model.addAttribute("repaymentmodMap", DictUtils.getDictByType(DictUtils.TFINANCEINFO_REPAYMENTMOD));
	      model.addAttribute("statusMap", DictUtils.getDictByType(DictUtils.TFINANCEINFO_STATUS));	
	      model.addAttribute("targettypeMap", DictUtils.getDictByType(DictUtils.TFINANCEINFO_TARGETTYPE));
		}
	
	/**
	 * 数据校验
	 * @param model
	 */
	private WebErrors validateSave(Tfinanceinfo tfinanceinfo, HttpServletRequest request) {
		WebErrors errors = WebErrors.create(request);
		/**if (errors.ifOutOfLength(username, "username", 1, 100)) {
			return errors;
		}  */    
		return errors;
	}
	

	@Resource
	private TfinanceinfoService tfinanceinfoService;   
	@Resource
	private TnoticeinforService tnoticeinforService;   
}